package com.ninghushangbao.ninghu.service.Impl;

import com.ninghushangbao.ninghu.entity.Join;
import com.ninghushangbao.ninghu.mapper.JoinMapper;
import com.ninghushangbao.ninghu.service.JoinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class JoinServiceImpl implements JoinService {

    @Autowired
    JoinMapper joinMapper;

    @Override
    public void addJoin(Join join) {
        join.setCreateTime(new Date());
        join.setUpdateTime(new Date());
        if(join.getStatus().equals("1")){
            join.setLaunchTime(new Date());
        }
        joinMapper.addJoin(join);
    }

    @Override
    public List<Join> selectJoin() {
        return joinMapper.selectJoin();
    }

    @Override
    public Join selectJoinById(int id) {
        return joinMapper.selectJoinById(id);
    }

    @Override
    public void updateJoin(Join join) {
        Join join1 = joinMapper.selectJoinById(join.getJoinId());
        if(join.getStatus().equals("1")&&join1.getStatus().equals("0")){
            join.setLaunchTime(new Date());
        }
        join.setUpdateTime(new Date());
        joinMapper.updateJoin(join);
    }

    @Override
    public void deleteJoinById(List<Integer> joinId) {
        joinMapper.deleteJoinById(joinId);
    }
}
